#include "wxsglcanvas.h"

namespace {
  wxsRegisterItem<wxsGLCanvas> Reg( _T( "GLCanvas" ), _T( "GLCanvas" ), wxsTWidget, _T( "对话框" ), 80, false );
  WXS_ST_BEGIN( wxsGLCanvasStyles, _T( "" ) )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
  WXS_EV_BEGIN( wxsGLCanvasEvents )
  WXS_EV_DEFAULTS()
  WXS_EV_END()
}

wxsGLCanvas::wxsGLCanvas( wxsItemResData* Data ):
  wxsWidget( Data, &Reg.Info, wxsGLCanvasEvents, wxsGLCanvasStyles ) {
  mRGBA = true;
  mBufferSize = 0;
  mLevel = 0;
  mDoubleBuffer = true;
  mStereo = false;
  mAuxBuffers = 0;
  mMinRed = 0;
  mMinGreen = 0;
  mMinBlue = 0;
  mMinAlpha = 0;
  mDepthSize = 16;
  mStencilSize = 0;
  mMinAccumRed = 0;
  mMinAccumGreen = 0;
  mMinAccumBlue = 0;
  mMinAccumAlpha = 0;
}


void wxsGLCanvas::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/glcanvas.h>" ), GetInfo().ClassName, 0 );
      wxString aname = GetCoderContext()->GetUniqueName( _T( "GLCanvasAttributes" ) );
      Codef( _T( "int %v[] = {\n" ), aname.wx_str() );
      if( mRGBA ) {
        Codef( _T( "\tWX_GL_RGBA,\n" ) );
      }
      if( !mRGBA && mBufferSize > 0 ) {
        Codef( _T( "\tWX_GL_BUFFER_SIZE,     %d,\n" ), mBufferSize );
      }
      if( mLevel ) {
        Codef( _T( "\tWX_GL_LEVEL,           %d,\n" ), mLevel );
      }
      if( mDoubleBuffer ) {
        Codef( _T( "\tWX_GL_DOUBLEBUFFER,\n" ) );
      }
      if( mStereo ) {
        Codef( _T( "\tWX_GL_STEREO,\n" ) );
      }
      if( mAuxBuffers > 0 ) {
        Codef( _T( "\tWX_GL_AUX_BUFFERS,     %d,\n" ), mAuxBuffers );
      }
      if( mMinRed > 0 ) {
        Codef( _T( "\tWX_GL_MIN_RED,         %d,\n" ), mMinRed );
      }
      if( mMinGreen > 0 ) {
        Codef( _T( "\tWX_GL_MIN_GREEN,       %d,\n" ), mMinGreen );
      }
      if( mMinBlue > 0 ) {
        Codef( _T( "\tWX_GL_MIN_BLUE,        %d,\n" ), mMinBlue );
      }
      if( mMinAlpha > 0 ) {
        Codef( _T( "\tWX_GL_MIN_ALPHA,       %d,\n" ), mMinAlpha );
      }
      if( mDepthSize >= 0 ) {
        int size = ( mDepthSize <= 16 ) ? 16 : 32;
        Codef( _T( "\tWX_GL_DEPTH_SIZE,      %d,\n" ), size );
      }
      if( mStencilSize >= 0 ) {
        Codef( _T( "\tWX_GL_STENCIL_SIZE,    %d,\n" ), mStencilSize );
      }
      if( mMinAccumRed > 0 ) {
        Codef( _T( "\tWX_GL_MIN_ACCUM_RED,   %d,\n" ), mMinAccumRed );
      }
      if( mMinAccumGreen > 0 ) {
        Codef( _T( "\tWX_GL_MIN_ACCUM_GREEN, %d,\n" ), mMinAccumGreen );
      }
      if( mMinAccumBlue > 0 ) {
        Codef( _T( "\tWX_GL_MIN_ACCUM_BLUE,  %d,\n" ), mMinAccumBlue );
      }
      if( mMinAccumAlpha > 0 ) {
        Codef( _T( "\tWX_GL_MIN_ACCUM_ALPHA, %d,\n" ), mMinAccumAlpha );
      }
      Codef( _T( "\t0, 0 };\n" ) );
      Codef( _T( "%C(%W, %I, %P, %S, %T, %N, %v);\n" ), aname.wx_str() );
      BuildSetupWindowCode();
      break;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsGLCanvas::OnBuildCreatingCode" ), GetLanguage() );
    }
  };
}

wxObject* wxsGLCanvas::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxPanel* gc = new wxPanel( Parent, GetId(), Pos( Parent ), Size( Parent ), Style() );
  SetupWindow( gc, Flags );
  return gc;
}


void wxsGLCanvas::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  WXS_BOOL( wxsGLCanvas, mRGBA,          _T( "Use True Color" ),               _T( "mRGBA" ),          true )
  WXS_LONG( wxsGLCanvas, mBufferSize,    _T( "Bits for buffer " ),             _T( "mBufferSize" ),    0 )
  WXS_LONG( wxsGLCanvas, mLevel,         _T( "Main Buffer" ),                  _T( "mLevel" ),         0 )
  WXS_BOOL( wxsGLCanvas, mDoubleBuffer,  _T( "Use doublebuffer" ),             _T( "mDoubleBuffer" ),  true )
  WXS_BOOL( wxsGLCanvas, mStereo,        _T( "Stereoscopic display" ),         _T( "mStereo" ),        false )
  WXS_LONG( wxsGLCanvas, mAuxBuffers,    _T( "Auxiliary buffers count" ),      _T( "mAuxBuffers" ),    0 )
  WXS_LONG( wxsGLCanvas, mMinRed,        _T( "Red color bits" ),               _T( "mMinRed" ),        0 )
  WXS_LONG( wxsGLCanvas, mMinGreen,      _T( "Green color bits" ),             _T( "mMinGreen" ),      0 )
  WXS_LONG( wxsGLCanvas, mMinBlue,       _T( "Blue color bits" ),              _T( "mMinBlue" ),       0 )
  WXS_LONG( wxsGLCanvas, mMinAlpha,      _T( "Alpha bits" ),                   _T( "mMinAlpha" ),      0 )
  WXS_LONG( wxsGLCanvas, mDepthSize,     _T( "Bits for Z-buffer (0,16,32)" ),  _T( "mDepthSize" ),     0 )
  WXS_LONG( wxsGLCanvas, mStencilSize,   _T( "Bits for stencil buffer " ),     _T( "mStencilSize" ),   0 )
  WXS_LONG( wxsGLCanvas, mMinAccumRed,   _T( "Accumulator Red color bits" ),   _T( "mMinAccumRed" ),   0 )
  WXS_LONG( wxsGLCanvas, mMinAccumGreen, _T( "Accumulator Green color bits" ), _T( "mMinAccumGreen" ), 0 )
  WXS_LONG( wxsGLCanvas, mMinAccumBlue,  _T( "Accumulator Blue color bits" ),  _T( "mMinAccumBlue" ),  0 )
  WXS_LONG( wxsGLCanvas, mMinAccumAlpha, _T( "Accumulator Alpha bits" ),       _T( "mMinAccumAlpha" ), 0 )
}
